package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.ArrEntity;
import com.sgb.kjwl.model.entity.user.UnitEntity;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class ArrAdapter extends BaseRecycleAdapter<ArrEntity> {

    private ClickArr clickArr;
    private boolean isReset = false;

    public ArrAdapter(Context context, List<ArrEntity> datas) {
        super(context, R.layout.item_arr, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final ArrEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemInputTextView arrTv = holder.getItem().findViewById(R.id.item_tv_arr);
        if (entity.getIsfill() != null && 1 == entity.getIsfill()) {
            arrTv.setStarTvVisibleOrGone(View.VISIBLE);
        } else {
            arrTv.setStarTvVisibleOrGone(View.GONE);
        }
        arrTv.setLabelName(entity.getName());
        arrTv.setLabelHint("请选择");

        if (holder.getPosition() == datas.size() - 1) {
            arrTv.setDeliverLineVG(false);
        } else {
            arrTv.setDeliverLineVG(true);
        }
        arrTv.setContent(entity.getContent());
        if (isReset) {
            arrTv.setContent("");
        }
        arrTv.setOnWholeItemClickListener(view -> {
            isReset = false;
            clickArr.clickArr(entity.getType(), holder.getPosition(), entity.getName(), entity.getId());
        });
    }

    public interface ClickArr {
        void clickArr(List<ArrEntity.ChildType> childType, int index, String pName, String pId);
    }

    public void OnClickArr(ClickArr clickArr) {
        this.clickArr = clickArr;
    }


    public void updateStatus(int index, String Content) {
        datas.get(index).setContent(Content);
        notifyDataSetChanged();
    }

    public void isReset(boolean isReset) {
        this.isReset = isReset;
    }
}
